const http = require('http');
const fs = require('fs');

const server = http.createServer((req, res) => {
  // 设置响应头(指定UTF-8编码)
  res.writeHead(200, {
    'Content-Type': 'text/plain; charset=utf-8'
  });
  
  // 创建可读流并管道传输到响应
  const readStream = fs.createReadStream('js流2/data.txt');
  readStream.pipe(res);
});

server.listen(8081, () => {
  console.log('服务器运行在 http://localhost:8081');
});